<template>
  <div class="con">
    <div class="contbox6_10">
      <p class="titlelist6_10">
        积分管理
        <span style="color: #999">&nbsp;&nbsp;/&nbsp;&nbsp;</span>基础配置
      </p>
      <div class="content">
        <div class="box">
          <div class="title">积分过期设置</div>
          <div class="container">
            <el-radio-group v-model="data.expiredFlag">
              <el-radio :label="0">永久有效</el-radio>
              <div style="clear: both; height: 15px"></div>
              <el-radio :label="1">
                每年固定时间清除所有积分 清除事件：12月31日
              </el-radio>
            </el-radio-group>
          </div>
          <div class="title" style="margin-top: 30px">积分计算规则设置</div>
          <div class="container">
            <el-input
            @input="value=>{data.inSco=value.replace(/[^\d]+/g,'')}"
              v-model="data.inSco"
              class="input"
              placeholder=""
            ></el-input
            >&nbsp;积分等于1元
          </div>
        </div>
        <div class="btnGroup">
          <el-button type="primary" @click="submits">确认</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      // 传递的数据
      data: {
        expiredFlag: 0, //有效期  0永久有效  1定时清理
        inSco: "",
        inAmt: 1,
      },
      // 判断是修改还是创建
      status: "0", //0创建  1修改
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      axios
        .post("scoOemRuleCfg/getOemConfig", {})
        .then((res) => {
          console.log(res);
          if (res.data.code == "0000") {
            // 有数据 要修改
            this.status = "1";
            res.data.data.expiredFlag = Number(res.data.data.expiredFlag);
            this.data = res.data.data;
          } else {
            // 没数据  走创建
            this.status = "0";
            return;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 提交 创建
    submits() {
      if (this.data.expiredFlag !== "" && this.data.inSco !== "") {
        let url;
        if (this.status == "0") {
          url = "scoOemRuleCfg/create";
        } else {
          url = "scoOemRuleCfg/modify";
        }
        axios
          .post(url, this.data)
          .then((res) => {
            console.log(res);
            if (res.data.code == "0000") {
              layer.open({
                content: res.data.msg,
                skin: "msg",
                time: 1, //1秒后自动关闭
              });
            } else {
              layer.open({
                content: res.data.msg,
                skin: "msg",
                time: 1, //1秒后自动关闭
              });
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }else{
        layer.open({
              content: '数据不能为空',
              skin: "msg",
              time: 1 //1秒后自动关闭
            });

      }
    },
  },
};
</script>

<style scoped>
.title {
  height: 40px;
  background: #f9fafc;
  line-height: 40px;
  margin-bottom: 20px;
  font-size: 18px;
  color: #303133;
  text-indent: 8px;
  font-family: "MicrosoftYaHei";
  color: #303133;
}
.box {
  padding: 0 20px;
  padding-top: 20px;
}
.container {
  padding-left: 10px;
}
.btnGroup {
  margin-left: 30px;
  margin-top: 20px;
}
/deep/ .input {
  width: 100px;
}
/deep/ .input .el-input__inner {
  width: 100%;
}
</style>